package com.soundai.skill.helloworld.helper;

import com.amazonaws.util.Base64;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;


public class Utils {

    /**
     * base64解密
     * @param args
     * @return
     */
    public static byte[] decodeByteBase64(String args){
        byte[] bytes = Base64.decode(args);
        return  bytes;
    }

    /**
     * base64加密
     * @param args
     * @return
     */
    public static byte[] encodeByteBase64(String args){
        byte[] data = Base64.encode(args.getBytes());
        return data;
    }


    public  static  String base64(String args){

        String ret = (new sun.misc.BASE64Encoder()).encode( args.getBytes() );
        return ret;
    }

    public static String[] splitData(String args,String splitChar){
        String[] strArr = args.split(splitChar);
        return strArr;
    }

    public static  String encodeUriString(String value) {
        String encodeData = null;
        try {
            encodeData = URLEncoder.encode(value, "UTF-8")
                    .replaceAll("\\+", "%20")
                    .replaceAll("\\!", "%21")
                    .replaceAll("\\'", "%27")
                    .replaceAll("\\(", "%28")
                    .replaceAll("\\)", "%29")
                    .replaceAll("\\~", "%7E");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return  encodeData;
    }

    public  static  String decodeUriString(String value){
        String decodeData = null;
        try {
            decodeData = URLDecoder.decode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return decodeData;
    }



}
